<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>显示当前系统时间</button>
    <div>显示事件</div>
    <p></p>
    <script>
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        var p = document.querySelector('p');
        btn.onclick = function(){
            div.innerText = getTime();
        }
        p.innerText = getTime();

        function getTime(){
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth();
            var dates = date.getDate();
            var arr = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
            var days = date.getDay();
            var time = year+"-"+month+"-"+dates+"-"+arr[days];
            return time;
        }
    </script>
</body>
</html>